<template>
  <div class="left">
    <div class="personal">
      <div class="avatar">
        <img :src=" userInfo?.avatar ? userInfo?.avatar : 'https://rs.dance365.com/default_head@3x.png?imageView2/0/w/100/h/100/format/webp/ignore-error/1'">
      </div>
      <div class="name-level">
        <div class="nickname">{{ userInfo?.account }}</div>
        <div class="level">
          <span class="lv"></span>
          <span class="count"></span>
        </div>
      </div>
      <div class="fans">
        <div class="fans-wrap">
          <div class="count">{{ userInfo?.statisticsBackup?.inviterCount ? userInfo?.statisticsBackup?.inviterCount : 0 }}</div>
          <div class="text">关注</div>
        </div>
        <div class="fans-wrap">
          <div class="count">{{ userInfo?.statisticsBackup?.fansCount ? userInfo?.statisticsBackup?.fansCount : 0 }}</div>
          <div class="text">粉丝</div>
        </div>
      </div>
    </div>
    <div class="menu">
      <div class="menu-item" :class="{ active: type == 'dynamics' }">
        <div class="line"></div>
        <router-link to="/my/dynamics">资源动态</router-link>
      </div>
    </div>
    <div class="menu">
      <div class="menu-item" :class="{ active: type == 'member' }" >
        <div class="line"></div>
        <router-link to="/member">我的会员</router-link>
      </div>
      <div class="menu-item" :class="{ active: type == 'wallet' }" >
        <div class="line"></div>
        <router-link to="">我的钱包</router-link>
      </div>
      <div class="menu-item" :class="{ active: type == 'coupon' }">
        <div class="line"></div>
        <router-link to="">我的优惠券</router-link>
      </div>
      <div class="menu-item" :class="{ active: type == 'order' }">
        <div class="line"></div>
        <router-link to="">我买的订单</router-link>
      </div>
      <div class="menu-item" :class="{ active: type == 'goods' }">
        <div class="line"></div>
        <router-link to="">我卖的</router-link>
      </div>
    </div>
    <div class="menu">
      <div class="menu-item" :class="{ active: type == 'information' }">
        <div class="line"></div>
        <router-link to="/center/information">我的资料</router-link>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import useUserInfoStore from '@/stores/modules/userInfo'
import type { UserInfoModel } from '@/api/userinfo'
const route = useRoute();
const type = ref('')
watch(route, (nval, oval) => {
  type.value = nval.meta.type as string
}, { immediate: true })

const userInfoStore = useUserInfoStore()
const userInfo = ref<UserInfoModel>()
onMounted(() => {
  userInfo.value = userInfoStore.userInfo as UserInfoModel
})
</script>

<style lang="less" scoped>
// 左侧菜单区
.left {
  width: 170px;
  margin-right: 10px;

  .personal {
    width: 100%;
    margin-bottom: 10px;
    padding: 21px 0;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;


    .avatar {
      width: 100px;
      height: 100px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }

    .name-level {
      width: 120px;
      height: 56px;
      padding: 6px 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      cursor: pointer;

      .nickname {
        width: 120px;
        text-align: center;
        color: #111;
      }

      .level {
        background: linear-gradient(#ff289b, #ff43d0);
        color: #fff;
        padding: 5px 8px;
        border-radius: 4px;
        display: flex;
        align-items: center;
        line-height: 1.15;

        .lv {
          width: 15px;
          height: 10px;
          background: url(../../image/level_Lv.png);
          background-size: 15px 10px;
        }

        .count {
          width: 8px;
          height: 10px;
          background: url(../../image/level_num_1.png);
          background-size: 8px 10px;
        }
      }
    }

    .fans {
      display: flex;
      justify-content: space-between;

      .fans-wrap {
        width: 85px;
        height: 59.5px;
        padding-top: 18px;
        box-sizing: border-box;
        text-align: center;

        .count {
          font-size: 16px;
          margin-bottom: 7px;
          color: #111;
        }

        .text {
          font-size: 14px;
          color: #7d8090;
        }
      }
    }
  }

  .menu {
    width: 100%;
    margin-bottom: 10px;

    .menu-item {
      width: 100%;
      padding: 17px 21px;
      background: #fff;
      position: relative;

      &.active .line {
        display: block;
      }
      &:hover .line {
        display: block;
      }

      &>a {
        font-size: 14px;
      }

      .line {
        width: 4px;
        height: 37px;
        position: absolute;
        background: #f93684;
        top: 50%;
        left: 0;
        transform: translate(0, -50%);
        display: none;
      }
    }
  }
}
</style>